#ifndef AUDIOPLAYER_H
#define AUDIOPLAYER_H

#include <QMap>
#include <QMediaPlayer>

#include "../global/xnamespace.h"

class QQmlEngine;
class QJSEngine;

X_BEGIN_NAMESPACE

// 音频播放器
class AudioPlayer : public QObject
{
    Q_OBJECT

public:
    enum SystemSoundType{
        LoginOk,
        LoginFailed,
        Logout,
        IncomingMessage,
        OutgoingMessage,
        SystemNotification,
        AudioCall,
        VideoCall,
        Screenshot
    };

public:
    static AudioPlayer &instance();
    static const char* qmlName();
    static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);

signals:
    void pause();
    void resume();
    void stop();

public slots:
    void playSystemSound(SystemSoundType type);
    void playAudioFile(const QString& fileName);

    void onPause();
    void onResume();
    void onStop();

private:
    explicit AudioPlayer(QObject *parent = 0);

    static AudioPlayer *createInstance();

    void initMediaPlayer();
    void initSystemSound();

private:
    QMediaPlayer m_player;

    QMap<SystemSoundType, QString> m_systemSounds;
};

X_END_NAMESPACE

#endif // AUDIOPLAYER_H
